<script setup lang="ts">
import type { GoodsListResult } from '@/api/works/types'
import { MoreFilled } from '@element-plus/icons-vue'

const list = inject<Ref<GoodsListResult[]>>('list')
const loading = inject('loading')

const checkList = ref<any>([])
const swithActive = inject<Ref<any>>('swithActive')

</script>

<template>
    <div class="works-grid" v-loading="loading">
        <el-empty description="暂无内容" v-if="list && list.length == 0" />
        <el-checkbox-group class="works-grid-list" v-model="checkList" size="large">
            <div v-for="item in list" :key="item.id" class="works-grid-item"
                :style="`background-image: url(${item?.image});`">
                <div class="mask">
                    <div class="mask-top">
                        <el-checkbox :value="item"></el-checkbox>
                        <el-dropdown :hide-on-click="false" popper-class="mask" :teleported="false">
                            <span>
                                <el-icon color="#ffffff" style="margin-top: 3px;cursor: pointer;" size="20">
                                    <MoreFilled />
                                </el-icon>
                            </span>
                            <template #dropdown>
                                <el-dropdown-menu>
                                    <el-dropdown-item v-if="swithActive == 1" :disabled="item.is_delete == 2"
                                        @click="$emit('on-edit', item)">编辑作品</el-dropdown-item>
                                    <el-dropdown-item v-if="swithActive == 1" :disabled="item.is_delete == 2"
                                        @click="$emit('on-exposure', item)">增加产品曝光</el-dropdown-item>
                                    <el-dropdown-item v-if="swithActive == 1" :disabled="item.is_delete == 2"
                                        @click="$emit('on-delete', item)">删除</el-dropdown-item>
                                    <el-dropdown-item :disabled="item.is_delete == 2"
                                        @click="$emit('go-front', item)">去前页</el-dropdown-item>
                                    <el-dropdown-item v-if="swithActive == 2"
                                        @click="$emit('on-cancellation', item)">取消搬运</el-dropdown-item>
                                    <!-- <el-dropdown-item>上传区块链存证</el-dropdown-item>
                                    <el-dropdown-item>下载区块链存证</el-dropdown-item> -->
                                </el-dropdown-menu>
                            </template>
                        </el-dropdown>
                    </div>
                    <div class="mask-bottom">
                        <div @click="$emit('on-edit', item)" v-if="swithActive == 1">编辑</div>
                        <div @click="$emit('on-delete', item)" v-if="swithActive == 1">删除</div>
                    </div>
                </div>
            </div>
        </el-checkbox-group>
    </div>
</template>

<style lang="scss" scoped>
.works-grid {
    min-width: 1000px;
    font-family: 'SOURCEHANSANSCN-EXTRALIGHT';

    div.works-grid-list {
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        gap: 20px;
        font-size: 16px;
        line-height: 1.5em;
    }

    .works-grid-item {
        background-color: #eeeeee;
        height: 200px;
        background-size: cover;
        border-radius: 5px;
        overflow: hidden;

        .mask {
            box-sizing: border-box;
            width: 100%;
            height: 100%;
            background-color: #00000059;
            padding: 0 20px;
            opacity: 0;
            transition: opacity .5s;
            display: flex;
            flex-direction: column;
            justify-content: space-between;
            border-radius: 5px;

            .mask-bottom {
                display: flex;
                justify-content: space-between;
                margin-bottom: 12px;
                color: #ffffff;
                font-size: 14px;
                padding: 0 30px;

                div {
                    cursor: pointer;
                }
            }

            .mask-top {
                display: flex;
                align-items: center;
                justify-content: space-between;
            }
        }

        &:hover .mask {
            opacity: 1;
        }
    }
}
</style>
